//清空实现
function resetQuery() {
    $("#userAccount").val(""),
        $("#userName").val(""),
        $("#sUserRole").val(""),
        $("#sUserBank").val(""),
        $("#sUserOrg").val(""),
        $("#userState").val("")
}


//查询银行
$(function () {
    var str="";
    $.ajax({
        url:"getBank",
        type:"POST",
        dataType:'json',
        success:function (data) {
            console.log(data.Bank.length);
            str="<option></option>";
            for (var i = 0; i <data.Bank.length ; i++) {
                str+="<option value='"+data.Bank[i].BANKNAME+"'>"+data.Bank[i].BANKNAME+"</option>";
            }
            $("#userState").html(str);
        }
    })
});

//查询产品
//查询产品名称
$(function () {
    var str = "";
    $.ajax({
        url: "getProduct",
        type: "POST",
        dataType: 'json',
        success: function (data) {
            // console.log(data);
            str="<option></option>";
            for (var i = 0; i <data.PHY.length; i++) {
                str+= "<option value='"+data.PHY[i].id+"'>"+data.PHY[i].LOANNAME+"</option>";
            }
            $("#sUserBank").html(str);
        }
    })
});
//查询
$("#queryBtn").click(function(){
    var filters = {
        'numbering':$("#userAccount").val(),
        'numbered':$("#userName").val(),
        'customerName':$("#sUserRole").val(),
        'product':$("#sUserBank").val(),
        'state':$("#sUserOrg").val(),
    };
    grid.jqGrid("setGridParam", { postData: filters ,page: 1});
    grid.trigger('reloadGrid');
});

//根据条件查询
$(function () {
    var pageNo = 1;
    var pageSize = 5;
    var grid_selector = "#grid-table";
    var pager_selector = "#grid-pager";
    //初始化数据表格
    grid = $(grid_selector).jqGrid({
        datatype: "json",
        url: 'getInformation',
        mtype: 'POST',
        page: pageNo,
        postData: {
            'numbering':$("#userAccount").val(),
            'numbered':$("#userName").val(),
            'customerName':$("#sUserRole").val(),
            'product':$("#userState").val(),
            'state':$("#sUserBank").val(),
        },
        height: 380,
        width: 300,
        colNames: ['贷款编号', '客户编号', '客户名称',  '产品名称',"所属银行","费用（元）"],
        colModel: [
            {name: 'LoanNumber', index: 'LoanNumber', align: 'center', sortable: false},
            {name: 'ID', index: 'ID', align: 'center', sortable: false},
            {name: 'CUSTOMERNAME', index: 'CUSTOMERNAME', align: 'center', sortable: false,},
            {name: 'LOANNAME', index: 'LOANNAME', align: 'center', sortable: false},
            {name: 'Bankname', index: 'Bankname', align: 'center', sortable: false},
            {name: '"1"', index: '"1"', align: 'center', sortable: false}
        ],
        viewrecords: true,
        rowNum: pageSize,
        rownumbers: false,//添加左侧行号
        rowList: [5, 10, 15],
        pager: pager_selector,
        altRows: true,
        multiselect: false,
        loadComplete: function (data) {
            var table = this;
            setTimeout(function () {
                updatePagerIcons(table);
            }, 0);
            var h = $(window).height() - ($('#grid-pager')[0].offsetHeight + 15) - ($('.result-table .box')[0].offsetTop + $('.ui-jqgrid-bdiv')[0].offsetTop + 3);
            $('.ui-jqgrid-bdiv').height(h);
        },
        autowidth: true,
        jsonReader: jsonReader,   // json中代表实际模型数据的入口
        rownumWidth: 55,
        prmNames: prmNames,
        recordtext: "显示 {0} - {1} 条 , 共 {20} 条",
        emptyrecords: "没有记录",
        /*loadtext: "正在加载...",*/
        pgtext: "第 {0} 页  ,共 {1} 页"
    });
    //初始化分页条
    showNavGrid(grid_selector, pager_selector);
});